package com.example.lottery.config;

import com.example.lottery.enums.HttpCodeEnum;
import com.example.lottery.exception.BusinessException;
import lombok.SneakyThrows;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;


/**
 * -- Created with IntelliJ IDEA.
 * -- @REMARK: 参数校验
 * -- @Author: tanwei
 * -- @Date: 2021/11/09/8:53 上午
 * -- @Description:
 */
@Aspect
@Component
public class ParameterAspect {

    @Pointcut("@annotation(com.example.lottery.bean.ParameterCalibration)")
    public void annotationPointCut() {
    }

    @SneakyThrows
    @Before("annotationPointCut()")
    public void before(JoinPoint joinPoint) {
        Object[] paramsArray = joinPoint.getArgs();
        Object param = paramsArray[0];
        if (param == null || param == "") {
            throw new BusinessException(HttpCodeEnum.BADREQUEST);
        }
    }


}
